package com.wz.project.system.help.controller;

import com.wz.common.utils.security.ShiroUtils;
import com.wz.framework.web.controller.BaseController;
import com.wz.framework.web.domain.AjaxResult;
import com.wz.framework.web.page.TableDataInfo;
import com.wz.project.system.help.domain.SysUserHelp;
import com.wz.project.system.help.service.SysUserHelpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zn kai
 * @create 2021-08-23 8:42
 */
@Controller
@RequestMapping("/system/help")
public class SysUserHelpController extends BaseController {

    private String prefix = "system/help";

    @Autowired
    private SysUserHelpService sysUserHelpService;

    @GetMapping()
    public String help() {
        return prefix + "/help";
    }


    /**
     * 查询用户反馈列表
     * @param userHelp
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysUserHelp userHelp) {
        startPage();
        List<SysUserHelp> list = sysUserHelpService.selectHelpList(userHelp);
        return getDataTable(list);
    }


    /**
     * 点击首页帮助  返回页面
     * @param modelMap
     * @return
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap){
        modelMap.put("user", ShiroUtils.getLoginName());
        return prefix + "/add";
    }

    /**
     * 新增保存
     * @param userHelp
     * @return
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysUserHelp userHelp){
        return toAjax(sysUserHelpService.insetUserHelp(userHelp));
    }



    /**
     * 修改公告
     */
    @GetMapping("/edit/{helpId}")
    public String edit(@PathVariable("helpId") Long helpId, ModelMap mmap)
    {
        mmap.put("help", sysUserHelpService.selectHelpById(helpId));
        return prefix + "/edit";
    }
}
